package com.mt.roll.wms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.dal.entity.SysDictData;
import com.mt.roll.core.dal.entity.SysDictType;
import com.mt.roll.core.dto.LoginUser;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.PlatformDictDataParam;
import com.mt.roll.wms.params.PlatformDictDataQueryParam;
import com.mt.roll.wms.params.PlatformDictTypeParam;
import com.mt.roll.wms.params.PlatformDictTypeQueryParam;
import com.mt.roll.wms.service.PlatformDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.groups.Default;
import java.util.List;

/**
 * 系统平台字典管理
 *
 * @author yangyang.jiang
 * @create 2018-11-12 19:50
 **/
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "platform-dict")
@Slf4j
@Api(value = "系统字典管理", tags = "系统字典管理", hidden = false)
public class PlatformDictController extends BaseController {

    @Autowired
    private PlatformDictService platformDictService;

    @PostMapping(value = "selectPlatformDictTypeListByPage")
    @ApiOperation(value = "分页查询系统字典类型管理", notes = "分页查询系统字典类型管理")
    public R<IPage> selectPlatformDictTypeListByPage(@Valid @RequestBody PlatformDictTypeQueryParam platformDictTypeQueryParams) {
        return platformDictService.selectPlatformDictTypeListByPage(platformDictTypeQueryParams);
    }

    @PostMapping(value = "savePlatformDictType")
    @ApiOperation(value = "保存字典类型", notes = "保存字典类型")
    public R<Object> savePlatformDictType(@Validated({AddGroup.class, Default.class}) @RequestBody PlatformDictTypeParam platformDictTypeParams) {
        LoginUser loginUser = getLoginUser();
        return platformDictService.savePlatformDictType(platformDictTypeParams, loginUser);
    }

    @PostMapping(value = "selectDictTypeById")
    @ApiOperation(value = "根据id查询字典类型", notes = "根据id查询字典类型")
    public R<SysDictType> selectDictTypeById(@Valid @RequestBody IdParam idParam) {
        return platformDictService.selectDictTypeById(idParam.getId());
    }

    @PostMapping(value = "selectDictTypeByList")
    @ApiOperation(value = "查询字典类型列表", notes = "查询字典类型列表")
    public R<List<SysDictType>> selectDictTypeByList(
    ) {
        return platformDictService.selectDictTypeByList();
    }

    @PostMapping(value = "updatePlatformDictType")
    @ApiOperation(value = "修改字典类型", notes = "修改字典类型")
    public R<Object> updatePlatformDictType(@Validated({UpdateGroup.class, Default.class}) @RequestBody PlatformDictTypeParam platformDictTypeParams) {
        LoginUser loginUser = getLoginUser();
        return platformDictService.updatePlatformDictType(platformDictTypeParams, loginUser);
    }

    @PostMapping(value = "deletePlatformDictType")
    @ApiOperation(value = "删除字典类型", notes = "删除字典类型")
    public R<Object> deletePlatformDictType(@Valid @RequestBody IdParam idParam) {
        return platformDictService.deletePlatformDictType(idParam.getId());
    }

    @PostMapping(value = "selectPlatformDictDataListByPage")
    @ApiOperation(value = "分页查询系统字典管理", notes = "分页查询系统字典管理")
    public R<IPage> selectPlatformDictDataListByPage(@Valid @RequestBody PlatformDictDataQueryParam platformDictDataQueryParams) {
        return platformDictService.selectPlatformDictDataListByPage(platformDictDataQueryParams);
    }

    @PostMapping(value = "savePlatformDictData")
    @ApiOperation(value = "保存字典信息", notes = "保存字典信息")
    public R<Object> savePlatformDictData(@Validated({AddGroup.class, Default.class}) @RequestBody PlatformDictDataParam platformDictDataParams) {
        LoginUser loginUser = getLoginUser();
        return platformDictService.savePlatformDictData(platformDictDataParams, loginUser);
    }

    @PostMapping(value = "selectPlatformDictDataById")
    @ApiOperation(value = "根据id查询数据字典", notes = "根据id查询数据字典")
    public R<SysDictData> selectPlatformDictDataById(
            @Valid @RequestBody IdParam idParam
    ) {
        return platformDictService.selectPlatformDictDataById(idParam.getId());
    }

    @PostMapping(value = "updatePlatformDictData")
    @ApiOperation(value = "修改字典信息", notes = "修改字典信息")
    public R<Object> updatePlatformDictData(@Validated({UpdateGroup.class, Default.class}) @RequestBody PlatformDictDataParam platformDictDataParams) {
        LoginUser loginUser = getLoginUser();
        return platformDictService.updatePlatformDictData(platformDictDataParams, loginUser);
    }

    @PostMapping(value = "deletePlatformDictData")
    @ApiOperation(value = "删除数据字典", notes = "删除数据字典")
    public R<Object> deletePlatformDictData(
            @Valid @RequestBody IdParam idParam) {
        return platformDictService.deletePlatformDictData(idParam.getId());
    }
}
